<!-- 编辑表格的单元 -->
<template>
  <div class="editable-cell">
    <div v-if="editable" class="editable-cell-input-wrapper">
      <a-input :value="value" @change="handleChange" @blur="check" @pressEnter="check" :maxLength="1000" />
      <!-- <a-icon type="check" class="editable-cell-icon-check" @click="check" /> -->
    </div>
    <div v-else class="editable-cell-text-wrapper">
      {{ value || ' ' }}
      <a-icon v-if="formType !== 'disable'" type="edit" class="editable-cell-icon" @click="edit" />
    </div>
  </div>
</template>

<script>
export default {
  name: 'EditableCell',
  props: {
    text: String,
    formType: String
  },
  data() {
    return {
      value: this.text,
      editable: false
    }
  },

  components: {},

  computed: {},

  watch: {
    formType: {
      handler(val) {
        val === 'disable' && (this.editable = false)
      },
      immediate: true
    }
  },

  created() {},

  mounted() {},

  methods: {
    handleChange(e) {
      const value = e.target.value
      this.value = value
      this.$emit('change', this.value)
    },
    check() {
      this.editable = false
      this.$emit('change', this.value)
    },
    edit() {
      this.value = this.value === '未填写' ? '' : this.value
      this.editable = true
    }
  }
}
</script>
<style lang='less' scoped>
</style>